package cn.zzuli.myfirstapp;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.view.Menu;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity<MainActivityActivity> extends AppCompatActivity {
    private EditText et_username;
    private EditText et_password;
    private String name,pwd;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initEvent();
    }

    private void initEvent() {
        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog1();
            }
        });
        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog2();
            }
        });
    }

    private void showDialog1() {
        et_username =(EditText) findViewById(R.id.textView);
        et_password =(EditText) findViewById(R.id.textView2);
        name = et_username.getText().toString().trim();
        pwd = et_password.getText().toString().trim();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if(TextUtils.isEmpty(name)||TextUtils.isEmpty(pwd)){
            builder.setMessage("登录失败，输入不能为空");
        }
        else{
            builder.setMessage("登录成功");
        }
        builder.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();
    }


//    private void initEvent2() {
//        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//                //showDialog2();
//            }
//        });
//    }

     private void showDialog2() {
         Intent i = new Intent();
         i.setClass(MainActivity.this, MainActivity2.class);
         startActivity(i);
//        AlertDialog.Builder builder = new AlertDialog.Builder(this);
//        builder.setMessage("注册成功！");
//        builder.setPositiveButton("我知道了",
//                new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//
                    }
//                });
//        AlertDialog dialog = builder.create();
//        dialog.show();



}



